package com.xt.service.impl;

import com.xt.bean.CollectionArticle;
import com.xt.dao.CollectionArticleRepository;
import com.xt.service.CollectionArticleService;
import com.xt.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * Created by XT on 2018/5/4.
 */
@Service
public class CollectionArticleServiceImpl implements CollectionArticleService {

    @Autowired
    private CollectionArticleRepository car;

    @Override
    public void saveOrUpdateOne(CollectionArticle ca){

        if (StringUtils.isEmpty(ca.getId())){
            //新增
            ca.setCreateDate(new Date());
        }

        ca.setUpdateDate(new Date());
        car.save(ca);
    }

    @Override
    public void deleteOne(String id){
        //删除关联关系

        car.delete(id);
    }

    @Override
    public CollectionArticle getById(String id){
        return car.findOne(id);
    }

    @Override
    public Page<CollectionArticle> getCollectionArticleListByPage(int count, int pageNo, String sortDirection, String... sortField) {
        Page<CollectionArticle> collectionArticlesPage = car.findAll(PageUtil.getPageable(count,pageNo,sortDirection,sortField));
        return collectionArticlesPage;
    }



}

